//
//  File.swift
//
//
//  Created by didi on 2022/9/8.
//

import MolecularObjects
import Vapor

public extension HookArguments {
    var req: Request {
        get {
            self["req"] as! Request
        }
        set {
            self["req"] = newValue
        }
    }

    var app: Application {
        get {
            self["app"] as! Application
        }
        set {
            self["app"] = newValue
        }
    }

    var routes: RoutesBuilder {
        get {
            self["routes"] as! RoutesBuilder
        }
        set {
            self["routes"] = newValue
        }
    }

    var permission: Permission {
        get {
            self["permission"] as! Permission
        }
        set {
            self["permission"] = newValue
        }
    }

    var metadata: Metadata {
        get {
            self["metadata"] as! Metadata
        }
        set {
            self["metadata"] = newValue
        }
    }

    var installInfo: SystemInstallInfo {
        SystemInstallInfo(currentStep: req.molecular.config.install.currentStep,
                          nextStep: nextInstallStep,
                          performStep: req.query[req.molecular.config.install.nextQueryKey] ?? false)
    }
}

extension HookArguments {
    var nextInstallStep: String {
        get {
            self["next-install-step"] as! String
        }
        set {
            self["next-install-step"] = newValue
        }
    }

    var currentInstallStep: String {
        get {
            self["current-install-step"] as! String
        }
        set {
            self["current-install-step"] = newValue
        }
    }
}
